package main

import "fmt"

func main() {
	fmt.Println(validateStackSequences([]int{2, 1, 0}, []int{1, 2, 0}))
}

func validateStackSequences(pushed []int, popped []int) bool {
	popCount := 0
	stack := []int{}
	for _, pushItem := range pushed {
		stack = append(stack, pushItem)
		if stack[len(stack)-1] == popped[popCount] {
			popCount++
			stack = stack[:len(stack)-1]
			for len(stack) != 0 && stack[len(stack)-1] == popped[popCount] {
				popCount++
				stack = stack[:len(stack)-1]
			}
		}
	}
	if len(stack) != 0 {
		return false
	}
	return true
}
